<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;

/**
 * 首页
 * @internal
 */
class Database extends Backend
{

    protected $noNeedLogin = [];
    protected $noNeedRight = [];
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 首页
     */
    public function index()
    {
        //$result = Db::query('call add_data2()');

        $tables = $this->initTablesData();

        $this->view->assign('tables', $tables);
        return $this->view->fetch();
    }

    /**
     * 读取数据库信息
     */
    private function initTablesData()
    {
        //获取数据库表名称列表
        //$tables = Db::connect('db2')->query('SHOW TABLE STATUS ');
        $tables = Db::query('SHOW TABLE STATUS ');
        foreach ($tables as $key => $table) {
            //获取改表的所有字段信息
            //$columns = Db::connect('db2')->query("SHOW FULL FIELDS FROM `".$table['Name']."`");
            $columns = Db::query("SHOW FULL FIELDS FROM `".$table['Name']."`");
            $table['columns'] = $columns;
            $tables[$key] = $table;
        }
        return $tables;
    }


}
